package com.ytf.test.fifth;

/**
 * @author: YTF
 * @date: 2024/9/18 17:48
 * @version: 1.0
 * @description:
 */
public class Flower {
    int petalCount = 0;
    String s = "initial value";

    public Flower() {
        this(47,"hi");
        System.out.println("default constructor (no args)");
    }

    public Flower(int petalCount) {
        this.petalCount = petalCount;
        System.out.println("Constructor w/ int arh only . petalCount="+petalCount);
    }

    public Flower(String s) {
        this.s = s;
        System.out.println("Constructor w/ String arg only. s="+s);
    }

    public Flower(int petalCount, String s) {
        this(petalCount);
        //! this(s); // Can't call two
        this.s=s;
        System.out.println("String & int args");
    }

    void printPetalCount(){
        // this(11); // Not inside non-constructor!
        System.out.println("petalCount = "+petalCount+" s= "+s);
    }

    public static void main(String[] args) {
        Flower flower = new Flower();
        flower.printPetalCount();

        /**
         * Output:
         * Constructor w/ int arh only . petalCount=47
         * String & int args
         * default constructor (no args)
         * petalCount = 47 s= hi
         *
         * 总结：
         *  this可以构造器中调用构造器，但只能在起始处调用一个
         *  如果传参和数据成员名字相同，用this. 可以区分。
         */
    }
}
